package com.xxgc.mq.controller;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 消息队列的生产者
 */
@RestController
@RequestMapping("/mq")
public class RabbitMQProvider {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/sendMessage")
    public String sendMessage(){
        for (int i = 0; i < 500; i++) {
            Map<String, String> map = new HashMap<>();
            map.put("message","你不要给我哇哇叫,黑得到我哇"+i);
            map.put("sendTime","2023-12-01 11:53:02");
            rabbitTemplate.convertAndSend("study_exchange","spz",map);
        }
        return "发送成功";
    }

}
